🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / common / src / commonMain / kotlin / org / meshtastic / core / common / util / Crc32.kt
Displaying Raw • Download
core/common/src/commonMain/kotlin/org/meshtastic/core/common/util/Crc32.kt 2d20cd8a4708e2ef66e98d5259f3a97ec93f240a (2d20cd8a) Text, 2.06 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.common.util
Tff7b72import T7ee787okio.ByteString
T8b949e/**
* CRC-32 (IEEE 802.3 / zlib): reflected polynomial 0xEDB88320, initial value and final XOR 0xFFFFFFFF.
*
* Matches the firmware's `crc32Buffer` (ErriezCRC32), which firmware 2.8+ uses to derive the node number from the
* device public key: `my_node_num = crc32(config.security.public_key)` (NodeDB::createNewIdentity). Lets the app
* recognize a pubkey-derived ("canonical") node number when a node reappears under a new num after a firmware upgrade.
*/
Tff7b72object T56d364Crc32 Tb4b4b4{
Tff7b72private Tff7b72const Tff7b72val Te6edf3POLYNOMIALTb4b4b4: Te6edf3UInt Tff7b72= T79c0ff0Te6edf3xEDB88320u
Tff7b72private Tff7b72const Tff7b72val Te6edf3INITIALTb4b4b4: Te6edf3UInt Tff7b72= T79c0ff0Te6edf3xFFFFFFFFu
Tff7b72private Tff7b72const Tff7b72val Te6edf3BITS_PER_BYTE Tff7b72= T79c0ff8
Tff7b72private Tff7b72const Tff7b72val Te6edf3BYTE_MASKTb4b4b4: Te6edf3UInt Tff7b72= T79c0ff0Te6edf3xFFu
Tff7b72private Tff7b72const Tff7b72val Te6edf3TABLE_SIZE Tff7b72= T79c0ff2T79c0ff5T79c0ff6
Tff7b72private Tff7b72val Te6edf3table Tff7b72=
Te6edf3UIntArrayTb4b4b4(Te6edf3TABLE_SIZETb4b4b4) Tb4b4b4{ Te6edf3index Tff7b72-Tff7b72>
Tff7b72var Te6edf3crc Tff7b72= Te6edf3indexTb4b4b4.Te6edf3toUIntTb4b4b4(Tb4b4b4)
Te6edf3repeatTb4b4b4(Te6edf3BITS_PER_BYTETb4b4b4) Tb4b4b4{ Te6edf3crc Tff7b72= Tff7b72if Tb4b4b4(Te6edf3crc Te6edf3and T79c0ff1Te6edf3u Tff7b72!Tff7b72= T79c0ff0Te6edf3uTb4b4b4) Tb4b4b4(Te6edf3crc Te6edf3shr T79c0ff1Tb4b4b4) Te6edf3xor Te6edf3POLYNOMIAL Tff7b72else Te6edf3crc Te6edf3shr T79c0ff1 Tb4b4b4}
Te6edf3crc
Tb4b4b4}
Tff7b72fun Td2a8ffcomputeTb4b4b4(Te6edf3bytesTb4b4b4: Te6edf3ByteStringTb4b4b4)Tb4b4b4: Te6edf3UInt Tb4b4b4{
Tff7b72var Te6edf3crc Tff7b72= Te6edf3INITIAL
Tff7b72for Tb4b4b4(Te6edf3i Tff7b72in T79c0ff0 Te6edf3until Te6edf3bytesTb4b4b4.Te6edf3sizeTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3byte Tff7b72= Te6edf3bytesTff7b72[Te6edf3iTff7b72]Tb4b4b4.Te6edf3toUIntTb4b4b4(Tb4b4b4) Te6edf3and Te6edf3BYTE_MASK
Te6edf3crc Tff7b72= Tb4b4b4(Te6edf3crc Te6edf3shr Te6edf3BITS_PER_BYTETb4b4b4) Te6edf3xor Te6edf3tableTff7b72[Tb4b4b4(Tb4b4b4(Te6edf3crc Te6edf3xor Te6edf3byteTb4b4b4) Te6edf3and Te6edf3BYTE_MASKTb4b4b4)Tb4b4b4.Te6edf3toIntTb4b4b4(Tb4b4b4)Tff7b72]
Tb4b4b4}
Tff7b72return Te6edf3crcTb4b4b4.Te6edf3invTb4b4b4(Tb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tff7b72fun Te6edf3ByteStringTb4b4b4.Td2a8ffcrc32Tb4b4b4(Tb4b4b4)Tb4b4b4: Te6edf3UInt Tff7b72= Te6edf3Crc32Tb4b4b4.Te6edf3computeTb4b4b4(Tff7b72thisTb4b4b4)
Served by rngit 1.5.0 - Generated in 0.04s